//
//  YZRecordManager.h
//  CocoaAsyncSocketClient
//
//  Created by lixiaoyi on 2018/6/22.
//  Copyright © 2018年 lixiaoyi. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>

#define shortRecord @"shortRecord"

typedef void(^YZRecordError)(NSError *error);
typedef void(^YZRecordCompletion)(NSString *finish);

@protocol YZRecordManagerDelegate<NSObject>

- (void)voiceDidPlayFinished;

@end

@interface YZRecordManager : NSObject<AVAudioRecorderDelegate,AVAudioPlayerDelegate>

@property (nonatomic, weak) id<YZRecordManagerDelegate> playDelegate;
@property (nonatomic, strong) AVAudioRecorder *recorder;
@property (nonatomic, strong) AVAudioPlayer *player;

@property (nonatomic, strong) YZRecordError recordError;
@property (nonatomic, strong) YZRecordCompletion recordFinish;

+ (YZRecordManager *)shareManager;

// 开始录音
- (void)startRecordWithFileName:(NSString *)fileName
                     completion:(YZRecordError)error;

// 结束录音
- (void)stopRecordCompletion:(YZRecordCompletion)completion;

- (void)pauseRecord;
- (void)resumeRecord;
// 是否拥有权限
- (BOOL)canRecord;

// 取消当前录制
- (void)cancelCurrentRecording;
- (void)removeCurrentRecordFile:(NSString *)fileName;

// 播放
- (void)startPlayRecorder:(NSString *)recorderPath;
- (void)stopPlayRecorder:(NSString *)recorderPath;
- (void)pause;

// 接收到的语音保存路径
- (NSString *)receiveVoicePathWithFileKey:(NSString *)fileKey;

// 获取语音时长
- (NSUInteger)durationWithVideo:(NSURL *)voiceUrl;
- (NSUInteger)getVideoDuration:(NSURL *)urlPath;

// 重新转换文件路径
- (NSString *)changeAudioPath:(NSString *)tempPath;

@end
